//
// Created by yfux on 2022/4/18.
//

#ifndef ICANLIVE_BASEPLAYER_H
#define ICANLIVE_BASEPLAYER_H

#include "JavaCallHelper.h"
#include "SafeQueue.h"

extern "C" {
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
};

class BasePlayer {
public:
    virtual void play() = 0;

    virtual void stop() = 0;

    virtual void decode() = 0;

    virtual ~BasePlayer();

public:
    BasePlayer();

    BasePlayer(int channelId, JavaCallHelper *helper, AVCodecContext *avCodecContext,
               AVRational &time_base);

    void setEnable(bool enable);

    static void releaseAvFrame(AVFrame *&avFrame);

    static void releaseAvPacket(AVPacket *&avPacket);

public:
    int channelId;
    JavaCallHelper *javaCallHelper;
    AVCodecContext *avCodecContext;
    AVRational time_base;
    SafeQueue<AVPacket *> avPacket_queue;
    SafeQueue<AVFrame *> avFrame_queue;
    bool isPlaying = false;
    double clock = 0;
};


#endif //ICANLIVE_BASEPLAYER_H
